﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace TanHuan.Authorize.Common
{
    public static class DataToJson
    {
        #region 根据DataTable生成Grid Json数据

        /// <summary>
        /// 根据DataTable生成Grid Json数据
        /// </summary>
        /// <param name="table">datatable</param>
        /// <param name="pItem">分页实体</param>
        /// <returns></returns>
        public static string GetGridJson(DataTable table, PageItem pItem)
        {
            string gridStr = "{\"total\":" + pItem.Count + ",\"rows\":";
            gridStr += JsonConvert.SerializeObject(table, new DataTableConverter());
            gridStr += "}";
            return gridStr;
        }
        #endregion
    }
}
